﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raise3000.Code.Attribute_Calculator;
using Raise3000.Code.Foundation;

namespace Raise3000.Code.Attribute_Calculator
{
    class Attr_ThreeBetCalculator : ICalculator
    {
        private Dictionary<string, long> threeBetOnThePreflop_ = new Dictionary<string,long>();
        private Dictionary<string, long> threeBetOnTheFlop_ = new Dictionary<string,long>();
        private Dictionary<string, long> threeBetOnTheTurn_ = new Dictionary<string, long>();
        private Dictionary<string, long> threeBetOnTheRiver_ = new Dictionary<string, long>();

        private Dictionary<string, long> threeBetOpportunitiesOnThePreflop_ = new Dictionary<string, long>();
        private Dictionary<string, long> threeBetOpportunitiesOnTheFlop_ = new Dictionary<string, long>();
        private Dictionary<string, long> threeBetOpportunitiesOnTheTurn_ = new Dictionary<string, long>();
        private Dictionary<string, long> threeBetOpportunitiesOnTheRiver_ = new Dictionary<string, long>();
        
        public Attr_ThreeBetCalculator()
        {
        }

        public override void DispatchAction(PlayerAction action, HandContextHelper hcHelper)
        {
            if (hcHelper.IsThereRaiseBehind())
            {
                // now the player is facing a 3bet opportunities
                bool does3Bet = (action.Move == ActionEnum.eRAISE);
                StreetEnum currentStreet = hcHelper.GetCurrentStreet();
                switch (currentStreet)
                {
                    case StreetEnum.ePREFLOP:
                        {
                            if (does3Bet)
                            {
                                threeBetOnThePreflop_[action.PlayerName]++;
                            }
                            threeBetOpportunitiesOnThePreflop_[action.PlayerName]++;
                            break;
                        };
                    case StreetEnum.eFLOP:
                        {
                            if (does3Bet)
                            {
                                threeBetOnTheFlop_[action.PlayerName]++;
                            }
                            threeBetOpportunitiesOnTheFlop_[action.PlayerName]++;
                            break;
                        };
                    case StreetEnum.eTURN:
                        {
                            if (does3Bet)
                            {
                                threeBetOnTheTurn_[action.PlayerName]++;
                            }
                            threeBetOpportunitiesOnTheTurn_[action.PlayerName]++;
                            break;
                        }
                    case StreetEnum.eRIVER:
                        {
                            if (does3Bet)
                            {
                                threeBetOnTheRiver_[action.PlayerName]++;
                            }
                            threeBetOpportunitiesOnTheRiver_[action.PlayerName]++;
                            break;
                        };
                };
            }
        }

        public override void RegisterPlayer(string playerTemplateName)
        {
            if (!threeBetOnThePreflop_.ContainsKey(playerTemplateName))
            {
                threeBetOnThePreflop_.Add(playerTemplateName, 0);
                threeBetOnTheFlop_.Add(playerTemplateName, 0);
                threeBetOnTheTurn_.Add(playerTemplateName, 0);
                threeBetOnTheRiver_.Add(playerTemplateName, 0);

                threeBetOpportunitiesOnThePreflop_.Add(playerTemplateName, 0);
                threeBetOpportunitiesOnTheFlop_.Add(playerTemplateName, 0);
                threeBetOpportunitiesOnTheTurn_.Add(playerTemplateName, 0);
                threeBetOpportunitiesOnTheRiver_.Add(playerTemplateName, 0);
            }
        }

        public override void OnStartHand(HandContextHelper hcHelper)
        {
            // nothing to do
        }

        public override void OnEndHand(HandContextHelper hcHelper)
        {
            // nothing to do
        }

        public override StatisticalAttribute CreateStatisticalAttribute(string player)
        {
            return new StatisticalAttribute("3Bet", 0);
        }
    }
}
